package cn.kickegg.log.core.service;

import cn.kickegg.log.core.model.LogEntry;
import cn.kickegg.log.core.spi.LogStorage;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
public class LogCollectorService {
    
    private final LogStorage logStorage;
    
    public LogCollectorService(LogStorage logStorage) {
        this.logStorage = logStorage;
    }
    
    @Async
    public void collectLog(String applicationName, String level, String message, 
                         String stackTrace, String className, String methodName, 
                         String threadName) {
        LogEntry logEntry = LogEntry.builder()
                .applicationName(applicationName)
                .level(level)
                .message(message)
                .stackTrace(stackTrace)
                .className(className)
                .methodName(methodName)
                .timestamp(LocalDateTime.now())
                .threadName(threadName)
                .build();
                
        logStorage.store(logEntry);
    }
} 